package com.jcl.recruit.core.common;

import com.jcl.core.constants.AttachmentConstant;
import com.jcl.core.ftp.FtpConfig;
import com.jcl.core.ftp.FtpProxy;
import com.jcl.core.utils.StringUtils;
import com.jcl.recruit.core.config.SystemConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * @ClassName FileFtpProxyFactory

 * @Author yyliu
 * @Date 2018/10/24 11:35
 * @Version 1.0
 **/
public class FileFtpProxyFactory {

    public static FtpConfig ftpConfig = new FtpConfig();

    private static final Logger logger = LoggerFactory.getLogger(FileFtpProxyFactory.class);

    public static FtpProxy getFtpProxy() throws IOException {

        FtpProxy proxy = new FtpProxy(getFtpConfig());

        return proxy;
    }

    public static FtpConfig getFtpConfig() throws IOException {

        ftpConfig.setServer(SystemConfig.getSystemFtpServer());
        if(StringUtils.hasLength(SystemConfig.getSystemFtpPort())){
            ftpConfig.setPort(Integer.valueOf(SystemConfig.getSystemFtpPort()));
        }
        ftpConfig.setUserName(SystemConfig.getSystemFtpUsername());
        ftpConfig.setPassword(SystemConfig.getSystemFtpPassword());
        ftpConfig.setLocation(SystemConfig.getSystemFtpLocation());

        return ftpConfig;
    }

    /* *
     * @Author yyliu
     * @Description //TODO
     * @Date 18:22 2018/10/23
     * @Param [corpCode, category, externalName]
     * @return java.lang.String
     **/
    public static String getRealFilePath(String corpCode, Integer category, String externalName){

        return ftpConfig.getLocation() + AttachmentConstant.SPLIT + corpCode + AttachmentConstant.SPLIT
                + category + AttachmentConstant.SPLIT + externalName;
    }

    /* *
     * @Author yyliu
     * @Description //TODO
     * @Date 18:22 2018/10/23
     * @Param [corpCode, category, externalName]
     * @return java.lang.String
     **/
    public static String getRealFilePath(String corpCode, Integer category){

        return ftpConfig.getLocation() + AttachmentConstant.SPLIT + corpCode + AttachmentConstant.SPLIT
                + category;
    }

    public static String getRealFilePathByFilePath(String filePath, String externalName){

        return filePath + AttachmentConstant.SPLIT
                + externalName;
    }
}
